import { Card, CardType, Color } from "../card";
import { LeBuSiShu } from "./delay";
import { NoDelayBrilliantness, GuoHeChaiQiao, ShunShouQianYang, WuXieKeJi, HuoGong, JieDaoShaRen, JueDou, WuZhongShengYou, TieSuoLianHuan, NanManRuQin, WanJianQiFa, TaoYuanJieYi, WuGuFengDeng } from "./nodelay";

function createCard<T extends Card>(target: CardType<T>, ...args: any[]): T {
    return new target(...args)
}

function addCards<T extends Card>(target: CardType<T>, color: Color, ...numbers: number[]): Card[] {
    const res = []
    for (const value of numbers) {
        const args: any[] = [color, value]
        const card: Card = createCard(target, ...args)
        res.push(card)
    }
    return res
}

function GuoHeChaiQiaoCardCreator(): Card[] {
    let res: Card[] = []
    res = res.concat(addCards(GuoHeChaiQiao, Color.SPADE, 3, 4, 12))
    res = res.concat(addCards(GuoHeChaiQiao, Color.CLUB, 3, 4))
    res = res.concat(addCards(GuoHeChaiQiao, Color.HEART, 12))
    
    return res
}

function ShunShouQianYangCardCreator(): Card[] {
    let res: Card[] = []
    res = res.concat(addCards(ShunShouQianYang, Color.SPADE, 3, 4, 12))
    res = res.concat(addCards(ShunShouQianYang, Color.DIAMOND, 3, 4))

    return res
}

function WuXieKeJiCardCreator(): Card[] {
    let res: Card[] = []
    res = res.concat(addCards(WuXieKeJi, Color.SPADE, 11, 13))
    res = res.concat(addCards(WuXieKeJi, Color.CLUB, 12, 13))
    res = res.concat(addCards(WuXieKeJi, Color.DIAMOND, 12))
    res = res.concat(addCards(WuXieKeJi, Color.HEART, 1, 13))
    return res
}

function HuoGongCardCreator(): Card[] {
    let res: Card[] = []
    res = res.concat(addCards(HuoGong, Color.HEART, 2, 3, 12))
    return res
}

function JieDaoShaRenCardCreator(): Card[] {
    let res: Card[] = []
    res = res.concat(addCards(JieDaoShaRen, Color.CLUB, 12, 13))
    return res
}

function JueDouCardCreator(): Card[] {
    const res: Card[] = []
    res.push(new JueDou(Color.SPADE, 1))
    res.push(new JueDou(Color.DIAMOND, 1))
    res.push(new JueDou(Color.CLUB, 1))
    return res
}

function WuZhongShengYouCardCreator(): Card[] {
    return addCards(WuZhongShengYou, Color.HEART, 7, 8, 9, 12)
}

function TieSuoLianHuanCardCreator(): Card[] {
    let res: Card[] = []
    res = res.concat(addCards(TieSuoLianHuan, Color.SPADE, 11,12))
    res = res.concat(addCards(TieSuoLianHuan, Color.CLUB, 10,11,12,13))
    return res
}

function NanManRuQinCardCreator(): Card[] {
    const res: Card[] = []
    res.push(new NanManRuQin(Color.SPADE, 7))
    res.push(new NanManRuQin(Color.CLUB, 7))
    res.push(new NanManRuQin(Color.SPADE, 13))
    return res
}

function WanJianQiFaCardCreator(): Card[] {
    return [new WanJianQiFa(Color.HEART, 1)]
}

function TaoYuanJieYiCardCreator(): Card[] {
    return [new TaoYuanJieYi(Color.HEART, 1)]
}

function WuGuFengDengCardCreator(): Card[] {
    return [new WuGuFengDeng(Color.HEART, 3), new WuGuFengDeng(Color.HEART, 4)]
}

function LeBuSiShuCardCreator(): Card[] {
    return [new LeBuSiShu(Color.HEART, 6), new LeBuSiShu(Color.SPADE, 6), new LeBuSiShu(Color.CLUB, 6)]
}

const BrilliantCardCreatorMap = new Map<string, () => Card[]>()


BrilliantCardCreatorMap.set(GuoHeChaiQiao.name, GuoHeChaiQiaoCardCreator)
BrilliantCardCreatorMap.set(ShunShouQianYang.name, ShunShouQianYangCardCreator)
BrilliantCardCreatorMap.set(WuXieKeJi.name, WuXieKeJiCardCreator)
BrilliantCardCreatorMap.set(HuoGong.name, HuoGongCardCreator)
BrilliantCardCreatorMap.set(JieDaoShaRen.name, JieDaoShaRenCardCreator)
BrilliantCardCreatorMap.set(JueDou.name, JueDouCardCreator)
BrilliantCardCreatorMap.set(WuZhongShengYou.name, WuZhongShengYouCardCreator)
BrilliantCardCreatorMap.set(TieSuoLianHuan.name, TieSuoLianHuanCardCreator)
BrilliantCardCreatorMap.set(NanManRuQin.name, NanManRuQinCardCreator)
BrilliantCardCreatorMap.set(WanJianQiFa.name, WanJianQiFaCardCreator)
BrilliantCardCreatorMap.set(TaoYuanJieYi.name, TaoYuanJieYiCardCreator)
BrilliantCardCreatorMap.set(WuGuFengDeng.name, WuGuFengDengCardCreator)
BrilliantCardCreatorMap.set(LeBuSiShu.name, LeBuSiShuCardCreator)

export default {
    BrilliantCardCreatorMap,
    NoDelayBrilliantness,
    GuoHeChaiQiao,
    ShunShouQianYang,
    WuXieKeJi,
    HuoGong,
    JieDaoShaRen,
    JueDou,
    WuZhongShengYou,
    TieSuoLianHuan,
    NanManRuQin,
    WanJianQiFa,
    TaoYuanJieYi,
    WuGuFengDeng,
    LeBuSiShu
}
